/****************************************************************
 * <strong>MFRandom基类</strong>
 *
 * <p>
 * MFRandom基类
 * </p>
 *
 * @author AndyZhang 2011 cnet2001@163.com
 * @version 0.1
 * ToDo:
 ***************************************************************/

package com.thinkwide.data.core;

import java.util.Random;
import java.util.UUID;

public class MFRandom {

    public final static String baseCharNumSeed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    public final static String baseNumSeed = "0123456789";
    public final static String baseCharSeed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String getRandomString(String seed, int length) {

        Random random = new Random();

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(seed.length());
            sb.append(seed.charAt(number));
        }
        return sb.toString();
    }

    public static int getRandomInt(int length) {

        Random random = new Random();
        int number = random.nextInt(length);
        return number;
    }

    public static String getRandomNString(int length) {
        return getRandomString(baseNumSeed, length);
    }

    public static String getRandomCString(int length) {
        return getRandomString(baseCharSeed, length);
    }

    public static String getRandomCNString(int length) {
        return getRandomString(baseCharNumSeed, length);
    }

    public static String getNewGuid() {
        UUID uuid = UUID.randomUUID();
        String guid = uuid.toString().replace("-", "").toUpperCase();
        return guid;
    }
}
